parsePOSIXTime ByteString conversion
authorJoey Hess <joeyh@joeyh.name>
Wed, 22 Jan 2025 20:41:06 +0000 (16:41 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 22 Jan 2025 20:42:09 +0000 (16:42 -0400)
Some easy (though tiny) speed wins.

Sponsored-by: Luke T. Shumaker on Patreon
13 files changed:
Annex/Content.hs
Annex/VectorClock.hs
Annex/VectorClock/Utility.hs
Assistant/DaemonStatus.hs
Command/Fsck.hs
Git/LsFiles.hs
Logs/AdjustedBranchUpdate.hs
Logs/Transfer.hs
Logs/Unused.hs
Logs/Upgrade.hs
Utility/InodeCache.hs
Utility/TimeStamp.hs
doc/todo/RawFilePath_conversion.mdwn

index 5a7a89ff107ed8896500ba4c60bbbedc3eeed7c7..3f26c0f0a8cb93e4f58ca5cf8bc45b441c1ced32 100644 (file)
@@ -108,6 +108,7 @@ import Utility.HumanTime
 import Utility.TimeStamp
 import Utility.FileMode
 import qualified Utility.RawFilePath as R
+import qualified Utility.FileIO as F
 
 import qualified System.FilePath.ByteString as P
 import System.PosixCompat.Files (isSymbolicLink, linkCount)
@@ -1086,7 +1087,7 @@ writeContentRetentionTimestamp key rt t = do
 readContentRetentionTimestamp :: RawFilePath -> Annex (Maybe POSIXTime)
 readContentRetentionTimestamp rt =
        liftIO $ join <$> tryWhenExists 
-               (parsePOSIXTime <$> readFile (fromRawFilePath rt))
+               (parsePOSIXTime <$> F.readFile' (toOsPath rt))
 
 {- Checks if the retention timestamp is in the future, if so returns
  - Nothing.
index db2c63c0bde55c0b51561b027ecae8ca596126e3..792f6e6e822c71ca70a7b9519f8beddd6ac7d176 100644 (file)
@@ -21,6 +21,7 @@ import qualified Annex
 import Utility.TimeStamp
 
 import Data.ByteString.Builder
+import qualified Data.ByteString as B
 import qualified Data.Attoparsec.ByteString.Lazy as A
 
 currentVectorClock :: Annex CandidateVectorClock
@@ -76,7 +77,7 @@ formatVectorClock (VectorClock t) = show t
 buildVectorClock :: VectorClock -> Builder
 buildVectorClock = string7 . formatVectorClock
 
-parseVectorClock :: String -> Maybe VectorClock
+parseVectorClock :: B.ByteString -> Maybe VectorClock
 parseVectorClock t = VectorClock <$> parsePOSIXTime t
 
 vectorClockParser :: A.Parser VectorClock
index 76b74d9cd57c85d7a37a8c3951ba0768ac9cc013..2c9f40f16e3f734cdb77d3a90eb065e97d6d66e1 100644 (file)
@@ -12,12 +12,13 @@ import Data.Time.Clock.POSIX
 import Types.VectorClock
 import Utility.Env
 import Utility.TimeStamp
+import Utility.FileSystemEncoding
 
 startVectorClock :: IO (IO CandidateVectorClock)
 startVectorClock = go =<< getEnv "GIT_ANNEX_VECTOR_CLOCK"
   where
        go Nothing = timebased
-       go (Just s) = case parsePOSIXTime s of
+       go (Just s) = case parsePOSIXTime (encodeBS s) of
                Just t -> return (pure (CandidateVectorClock t))
                Nothing -> timebased
        -- Avoid using fractional seconds in the CandidateVectorClock.
index dde5010f8c47930fb03f18d393a49d81d870778c..eeb40605ea569c1bfb983ff995db7b299d89431b 100644 (file)
@@ -136,13 +136,13 @@ readDaemonStatusFile file = parse <$> newDaemonStatus <*> readFile file
   where
        parse status = foldr parseline status . lines
        parseline line status
-               | key == "lastRunning" = parseval parsePOSIXTime $ \v ->
+               | key == "lastRunning" = parseval (parsePOSIXTime . encodeBS) $ \v ->
                        status { lastRunning = Just v }
                | key == "scanComplete" = parseval readish $ \v ->
                        status { scanComplete = v }
                | key == "sanityCheckRunning" = parseval readish $ \v ->
                        status { sanityCheckRunning = v }
-               | key == "lastSanityCheck" = parseval parsePOSIXTime $ \v ->
+               | key == "lastSanityCheck" = parseval (parsePOSIXTime . encodeBS) $ \v ->
                        status { lastSanityCheck = Just v }
                | otherwise = status -- unparsable line
          where
index 5924b4d11ea69e3c8e3eaf07be586c892cab71fa..f0f833117d4dd86e3c54efb85b9c43c63b47cd0d 100644 (file)
@@ -702,7 +702,7 @@ getStartTime u = do
        liftIO $ catchDefaultIO Nothing $ do
                timestamp <- modificationTime <$> R.getFileStatus f
                let fromstatus = Just (realToFrac timestamp)
-               fromfile <- parsePOSIXTime <$> readFile (fromRawFilePath f)
+               fromfile <- parsePOSIXTime <$> F.readFile' (toOsPath f)
                return $ if matchingtimestamp fromfile fromstatus
                        then Just timestamp
                        else Nothing
index 4eea39541a3ec824149fe81ca7c101673fbc827d..08c98b7fdaa4a7d211dde032491751accc9982e8 100644 (file)
@@ -373,4 +373,4 @@ inodeCaches locs repo = guardSafeForLsFiles repo $ do
                mkInodeCache
                        <$> (readish =<< M.lookup "ino:" m)
                        <*> (readish =<< M.lookup "size:" m)
-                       <*> (parsePOSIXTime =<< (replace ":" "." <$> M.lookup "mtime:" m))
+                       <*> (parsePOSIXTime =<< (encodeBS . replace ":" "." <$> M.lookup "mtime:" m))
index c7f2822945e2042f9209f3512fc73032f377da74..5b2ea9648a314d22338cdc076acc83210e50ec27 100644 (file)
@@ -80,5 +80,5 @@ parseAdjustLog l =
                        "1" -> Just True
                        "0" -> Just False
                        _ -> Nothing
-               t <- parsePOSIXTime ts
+               t <- parsePOSIXTime (encodeBS ts)
                return (b, t)
index 098ecb946528b0a3198d46c9d9ee34f488b93bd7..6ddd9350b23d2ac1b78dc9b0c300363abdbb9ce1 100644 (file)
@@ -320,7 +320,7 @@ readTransferInfo mpid s = TransferInfo
        bits = splitc ' ' firstline
        numbits = length bits
        time = if numbits > 0
-               then Just <$> parsePOSIXTime =<< headMaybe bits
+               then Just <$> parsePOSIXTime . encodeBS =<< headMaybe bits
                else pure Nothing -- not failure
        bytes = if numbits > 1
                then Just <$> readish =<< headMaybe (drop 1 bits)
index 5e8416a6054b6c731a27673cfd690023e33dc31d..fa2b2ce3ccac3418373aa56a3e40fa5944fca3bb 100644 (file)
@@ -81,7 +81,7 @@ readUnusedLog prefix = do
                , return M.empty
                )
   where
-       parse line = case (readish sint, deserializeKey skey, parsePOSIXTime ts) of
+       parse line = case (readish sint, deserializeKey skey, parsePOSIXTime (encodeBS ts)) of
                (Just int, Just key, mtimestamp) -> Just (key, (int, mtimestamp))
                _ -> Nothing
          where
index bdc4f40d90bc3c03bfed1903502a948a771a2fa9..bc63e0021f5784a51d86bfb4c1fc8cd13caa85dc 100644 (file)
@@ -39,7 +39,7 @@ readUpgradeLog = do
                , return []
                )
   where
-       parse line = case (readish sint, parsePOSIXTime ts) of
+       parse line = case (readish sint, parsePOSIXTime (encodeBS ts)) of
                (Just v, Just t) -> Just (RepoVersion v, t)
                _ -> Nothing
          where
index 3828bc645a4af2fb24c6ce7598a46f3cc994b916..6f8008dd5f06b247102a38ac3ee1a744681dac88 100644 (file)
@@ -185,7 +185,7 @@ readInodeCache s = case words s of
        (inode:size:mtime:mtimedecimal:_) -> do
                i <- readish inode
                sz <- readish size
-               t <- parsePOSIXTime $ mtime ++ '.' : mtimedecimal
+               t <- parsePOSIXTime $ encodeBS $ mtime ++ '.' : mtimedecimal
                return $ InodeCache $ InodeCachePrim i sz (MTimeHighRes t)
        _ -> Nothing
 
index 878d6f7299940ec4bd219c1466f249bb0711dadb..1175034e91cbc2c250da3210c17b8113861d4423 100644 (file)
@@ -19,7 +19,6 @@ import Data.Time
 import Data.Ratio
 import Control.Applicative
 import qualified Data.ByteString as B
-import qualified Data.ByteString.Char8 as B8
 import qualified Data.Attoparsec.ByteString as A
 import Data.Attoparsec.ByteString.Char8 (char, decimal, signed, isDigit_w8)
 
@@ -41,9 +40,9 @@ parserPOSIXTime = mkPOSIXTime
                        A.parseOnly (decimal <* A.endOfInput) b
                return (d, len)
 
-parsePOSIXTime :: String -> Maybe POSIXTime
-parsePOSIXTime s = eitherToMaybe $ 
-       A.parseOnly (parserPOSIXTime <* A.endOfInput) (B8.pack s)
+parsePOSIXTime :: B.ByteString -> Maybe POSIXTime
+parsePOSIXTime b = eitherToMaybe $ 
+       A.parseOnly (parserPOSIXTime <* A.endOfInput) b
 
 {- This implementation allows for higher precision in a POSIXTime than
  - supported by the system's Double, and avoids the complications of
index 6d08e95efde60d3b4a04138294cdcdd5ec79e6a5..a452c41dca2b76bd0cd11d9daad160d8e31bf6fb 100644 (file)
@@ -21,6 +21,10 @@ status.
   readFile, writeFile, and appendFile on FilePaths.
   Note that the FilePath versions do newline translation on windows, 
   which has to be handled when converting to the Utility.FileIO ones.
+* System.Directory.OsPath is available with OsPath build flag, but
+  not yet used, and would eliminate a lot of fromRawFilePaths.
+  Make Utility.SystemDirectory import it when built with OsPath,
+  and the remaining 6 hours or work will explain itself..
 
 [[!tag confirmed]]